package com.hexb.smh.mapper;

import com.hexb.smh.entity.Account;
import com.hexb.smh.entity.param.account.AccountQueryParam;
import com.hexb.smh.entity.view.SimpleAccount;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author : hexb
 * BaseMapper内置方法部分仅支持mysql
 */
@Mapper
@Repository
public interface AccountMapper {

    int save(Account account);

    @Select("select * from account where loginName=#{loginName} or phoneNo=#{loginName}")
    Account findByLoginNameOrPhoneNo(String loginName);

    List<Account> search(AccountQueryParam param);

    int updateByEntity(Account account);

    @Update("update account set lastLoginTime=now(),lastLoginIp=#{ip} where id=#{id}")
    int updateLoginTime(@Param("id") Integer id, @Param("ip") String ip);

    @Select("select * from account where id=#{id}")
    Account selectById(Integer id);

    @Delete("delete from account where id=#{id}")
    int delete(Integer id);

    @Select("select * from account where loginName=#{loginName}")
    Account selectByLoginName(String loginName);

    @Select("select * from account where phoneNo=#{phoneNo}")
    Account selectByPhoneNo(String phoneNo);

    int deleteBatch(@Param("ids") Integer[] ids);

    int updateEnableBatch(@Param("ids") Integer[] ids, @Param("enabled") Boolean enabled);

    Account findOneByMap(Map<?, ?> param);

    List<SimpleAccount> allAdmin(String searchKey);

    List<SimpleAccount> allAccount(String searchKey);

}
